package com.office.supplies.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.office.supplies.pojo.Buy;
import com.office.supplies.pojo.dto.SelectBuyListDTO;
import com.office.supplies.pojo.vo.BuyListVO;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @Author admin
 * @Description TODO
 * @Date 2023/12/11/0:52
 */
@Mapper
public interface BuyMapper  extends BaseMapper<Buy> {

    /**
     * 新增采购信息
     *
     * @param buy Buy
     */
    @Insert("insert into buy (goods_id, emp_id, buy_count, price, total_price, status) " +
            "value (#{goodsId},#{empId},#{buyCount},#{price},#{totalPrice},#{status})")
    void insertBuy(Buy buy);

    /**
     *根据id查询采购信息
     *
     * @param id Long
     * @return Buy
     */
    @Select("select * from buy where id = #{id}")
    Buy getBuyInfoById(Long id);

    /**
     * 删除采购信息
     *
     * @param id Long
     */
    @Delete("delete from buy where id = #{id}")
    void deleteById(Long id);

    /**
     * 根据goods_id删除采购信息
     *
     * @param goodsId Long
     */
    @Delete("delete from buy where goods_id = #{goodsId}")
    void deleteByGoodsId(Long goodsId);

    /**
     * 条件分页查询采购订单
     *
     * @param selectBuyListDTO SelectBuyListDTO
     * @return List<BuyListVO>
     */
    List<BuyListVO> selectBuyInfos(SelectBuyListDTO selectBuyListDTO);

    /**
     * 修改采购订单的price , totalPrice
     *
     * @param buy Buy
     */
    @Update("update buy set price = #{price}, total_price = #{totalPrice} where id = #{id}")
    void updateBuyInfo(Buy buy);

    /**
     * 采购订单数
     *
     * @return int
     */
    @Select("select count(id) from buy")
    int getBuyOrderCount();

    @Select("select count(goods_id) from warehouse.buy where goods_id = #{goodsId}")
    int selectBuyByGoodsId(Long goodsId);

}
